package com.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.service.NovelService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import com.beans.Book;
import com.beans.Novel;



@Controller
@RequestMapping("/novel")
public class NovelController {
    @Resource
    NovelService service;


    @GetMapping("/getbook")
    public String getbook(String userName, ModelMap m) {
        List<Novel> novel = service.getBook(userName);
        m.put("list", novel);
        return "front/bookshelf";
    }


    /***************** 【以下为修改部分内容】 *********************/

    @GetMapping("/toNovelPage")
    public String toNovelPage() {
        return "novel/allnovel";
    }

    @RequestMapping("/queryByPage")
    @ResponseBody
    public Map<String, Object> queryByPage(Novel novel, Integer page, Integer limit) {
        return service.queryByPage(novel, page, limit);
    }

    @RequestMapping("/addnovel")
    @ResponseBody
    public Integer addNovel(@RequestBody Novel novel) {
        return service.addNovel(novel);
    }

    @PostMapping("/gotoupdatenovel")
    @ResponseBody
    public Integer updateu(@RequestBody Novel novel) {
        return service.updateNovel(novel);
    }

    @RequestMapping("/deletenovel")
    @ResponseBody
    public Integer deleteu(int novelid) {
        return service.deleteNovel(novelid);
    }


    @RequestMapping("/deletebook")
    public String deletebook(String novelname,String userName) {
        service.deleteBook(novelname);
        return "forward:/novel/getbook";
    }

    @RequestMapping("/addbook")
    public String addBook(Book book,ModelMap m,String novelname) {
        service.addBook(book);
        Novel novel=service.getNovelByName(novelname);
        m.put("novel",novel);
        return "front/xiangqing";
    }
}
